package ar.edu.itba.it.pdc.monitoring;


//Hey guys! Remember to instantiate this in the very beginning so it starts recording!
public class ProxyMonitoring {

	private static ProxyMonitoring instance;
	
	private int bytesClientAndProxy;
	private int bytesServersAndProxy;
	private int allBlocks;
	private int ipBlocks;
	private int ipGroupBlocks;
	private int contentTypeBlocks;
	private int URIBlocks;
	private int sizeBlocks;
	private int l33tTransformations;
	private int imageTransformations;
	private int openConnections;
	
	protected ProxyMonitoring() {
	
	}
	
	public synchronized static ProxyMonitoring getInstance() {
		if (instance == null) {
			instance = new ProxyMonitoring();
		}
		
		return instance;
	}
	
	public int getBytesClientAndProxy() {
		return bytesClientAndProxy;
	}
	
	public void addBytesClientAndProxy(int bytes) {
		bytesClientAndProxy += bytes;
	}
	
	public int getBytesServersAndProxy() {
		return bytesServersAndProxy;
	}
	
	public void addBytesServersToProxy(int bytes) {
		bytesServersAndProxy += bytes;
	}
	
	public int getImageTransformations() {
		return imageTransformations;
	}
	
	public void addImageTransformations() {
		imageTransformations++;
	}
	
	public int getL33tTransformations() {
		return l33tTransformations;
	}
	
	public void addL33tTransformations() {
		l33tTransformations++;
	}
	
	public int getTotalBytes() {
		return bytesClientAndProxy + bytesServersAndProxy;
	}
	
	public int getBlocks() {
		return allBlocks + ipBlocks + ipGroupBlocks + URIBlocks + sizeBlocks + contentTypeBlocks;
	}
	
	public int getAllBlocks() {
		return allBlocks;
	}
	
	public void addAllBlock() {
		allBlocks++;
	}
	
	public int getIpBlocks() {
		return ipBlocks;
	}
	
	public void addIpBlock() {
		ipBlocks++;
	}
	
	public int getIpGroupBlocks() {
		return ipGroupBlocks;
	}
	
	public void addIpGroupBlock() {
		ipGroupBlocks++;
	}
	
	public int getContentTypeBlocks() {
		return contentTypeBlocks;
	}
	
	public void addContentTypeBlocks() {
		contentTypeBlocks++;
	}
	
	public int getSizeBlocks() {
		return sizeBlocks;
	}
	
	public void addSizeBlocks() {
		sizeBlocks++;
	}
	
	public int getURIBlocks() {
		return URIBlocks;
	}
	
	public void addURIBlock() {
		URIBlocks++;
	}
	
	public int getOpenConnections() {
		return openConnections;
	}
	
	public void openConnection() {
		openConnections++;
	}
	
	public void closeConnection() {
		openConnections--;
	}
	
	@Override
	public String toString() {
		return "Total bytes transfered: " + getTotalBytes() +
				"\nBytes transfered between clients and proxy: " + getBytesClientAndProxy() +
				"\nBytes transfered between proxy and origin servers: " + getBytesServersAndProxy() +
				"\nTotal blocks: " + getBlocks() +
				"\nTotal blocks with \"All\" condition: " + getAllBlocks() +
				"\nTotal blocks from a single destiny IP: " + getIpBlocks() +
				"\nTotal blocks from a destiny IP group: " + getIpGroupBlocks() +
				"\nTotal blocks from a URI pattern: " + getURIBlocks() +
				"\nTotal blocks by Content-Type: " + getContentTypeBlocks() +
				"\nTotal blocks by resource size: " + getSizeBlocks() +
				"\nTotal l33t transformations: " + getL33tTransformations() +
				"\nTotal images rotated: " + getImageTransformations() +
				"\nOpen connections: " + getOpenConnections() + "\n";
				
	}
}